package com.zjitc.mapper;

import com.zjitc.controller.UserController;
import com.zjitc.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;


@Mapper
public interface UserMapper {

	@Select("select * from user where username = #{username}")
	User findUserByName(String username);

	@Select("select * from user;")
	List<User> findAll();

	@Select("select * from user where role = #{role}")
	List<User> findUserByRole(int role);

	@Insert("insert into user values (null,#{username},#{password},0)")
	void insert(User user);

	@Delete("delete from user where id = #{index}")
	boolean delete(int index);

	@Update("update user set username = #{username}, password = #{password} where id = #{id}")
	boolean update(User user);

	@Select("select * from user where id = #{id}")
	User findUserById(int id);

	@Select("select b.id as id,b.name as name,b.status as status,b.position as position,h.last_bt as last_bt from book b right join history h on h.book_id=b.id and h.id=#{id}")
	List<UserController.BAH> findAllBAH(int id);
}
